#include <iostream>
#include <string.h>
using namespace std;

class Solution {
public:
    int reverse(int x) {
        bool b = x < 0 ? true : false;
        unsigned long long tmp;
        unsigned char buf[256] = {0};
        int i = 0;
        tmp = x;
        if (b)
            tmp = -tmp;
        while( tmp > 0)
        {
            buf[i] = tmp % 10 + '0';
            tmp /= 10;
            i++;
        }
        tmp &= 0;

        for (int j = 0; j < i; j++)
        {
            tmp += buf[j] - '0';
            if (j == i - 1)
                break;
            tmp *= 10;
        }
        if (tmp > 0x7fffffff)
            return 0; 
        if (b)
            tmp = -tmp;
        return int(tmp);

    }
};

int main()
{
    Solution sl;
    cout << "Input : -321 " << "Output : " << sl.reverse(1563847412) << endl;
    return 0;
}
